<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        body {
            background-color: #663399;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-box {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .login-box input {
            display: block;
            margin-bottom: 10px;
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        .login-box button {
            width: 48%;
            padding: 8px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="login-box">
        <h2>用户登录</h2>
        <form id="loginForm">
            <label for="username">用户名：</label>
            <input type="text" id="username" name="username">

            <label for="password">密码：</label>
            <input type="password" id="password" name="password">

            <button type="submit">提交</button>
            <button type="reset">重置</button>
        </form>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function(event) {
            event.preventDefault();

            var username = document.getElementById('username').value;
            var password = document.getElementById('password').value;

            // 必填项验证
            if (!username || !password) {
                alert('用户名和密码不能为空！');
                return;
            }

            // 有效性验证
            if (username.length < 8 || username.length > 20 || password.length < 8 || password.length > 20) {
                alert('用户名和密码的长度必须在8到20个字符之间！');
                return;
            }

            // 提交数据
            alert('登录成功！');
        });
    </script>
</body>
</html>